<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.chengxiaoxiao.commons.PageUtils" %>
<%@ page import="com.chengxiaoxiao.commons.Page" %>
<%@include file="/commons/header.jsp" %>


<div style="margin-left:210px;margin-top:65px;padding:10px 5px 0 5px;">

    <div style="line-height:26px;height:26px;margin-bottom:10px;">
        <h1 style="float:left;font-size:26px;">书籍管理</h1>

        <span class="layui-breadcrumb" style="float:right;font-size:12px;">
                <a href="#">首页</a>
                <a><cite>书籍管理</cite></a>
            </span>
    </div>


    <!--内容-----------------------------开始-------------------------------------------------->
    <div style="clear:both;margin-top:20px;">

    </div>


    <div style="clear:both;"></div>
    <div style="clear:both;margin-top:20px;">

        <form method="get" action="BookServlet">
            <div style="float:left;margin-right:20px;">
                <input type="hidden" name="op" value="listbook"/>
                <div class="layui-input-inline">
                    <input type="text" name="bookName" lay-verify="required" style="height:30px;" placeholder="请输入书籍名称"
                           autocomplete="off" class="layui-input" value="${bookName}">
                </div>
                <div class="layui-inline" style="margin-left:-4px;">
                    <button id="getbyNum" class="layui-btn layui-btn-normal layui-btn-small" lay-submit
                            style="height:30px;"><i
                            class="layui-icon">&#xe615;</i>
                    </button>
                </div>

            </div>
        </form>
    </div>
    <div style="clear:both;"></div>

    <table class="layui-table" lay-skin="row">
        <thead>
        <tr>
            <th>序号</th>
            <th>书籍名称</th>
            <th>作者</th>
            <th>出版社</th>
            <th>类别</th>
            <th>价格</th>
            <th>数量</th>
            <th>ISBN</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        <c:forEach items="${page.records}" var="b" varStatus="vs">
            <tr>
                <td width="7%">${vs.count}</td>
                <td width="15%">${b.bookName}</td>
                <td>${b.author}</td>
                <td>${b.publisher.name}</td>
                <td>${b.category.name}</td>
                <td>${b.price}</td>
                <td>${b.number}</td>
                <td>${b.isbn}</td>
                <td>
                    <button ids="${b.id}" class="layui-btn layui-btn-normal layui-btn-small notice">
                        查看
                    </button>

                    <button ids="${b.id}" class="layui-btn layui-btn-normal layui-btn-small edit"><i
                            class="layui-icon"> &#xe642;</i></button>

                    <button ids="${b.id}" class="layui-btn layui-btn-normal layui-btn-small delete"><i
                            class="layui-icon"></i></button>
                </td>

            </tr>
        </c:forEach>


        </tbody>

    </table>
    <div id="page1" style="clear: both; margin-top: 30px;" class="paginator">
        <%
            Page pages = (Page) request.getAttribute("page");
        %>
        <%=PageUtils.ShowPageNavigate(pages)%>
    </div>
    <br/><br/><br/><br/><br/><br/><br/><br/>

    <div id="demo1" style="margin-top:10px;"></div>


    <script type="text/javascript">

        $(function () {
            //查看详细信息
            $('.notice').on('click', function () {
                var item = $(this);
                var ids = item.attr("ids");

                layer.open({
                    type: 2,
                    title: '查看详细信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '520px'],
                    content: '${pageContext.request.contextPath}/manager/BookServlet?op=showbook&id=' + ids
                });
            });

            //编辑图书
            $('.edit').on('click', function () {
                var item = $(this);
                var ids = item.attr("ids");

                layer.open({
                    type: 2,
                    title: '编辑图书信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '520px'],
                    content: '${pageContext.request.contextPath}/manager/BookServlet?op=showeditBook&id=' + ids
                });
            });


            //删除逻辑
            $(".delete").click(function () {


                var check = confirm("确认要删除吗？");

                if (!check) {
                    return;
                }
                var item = $(this);

                var id = item.attr("ids");

                $.post("${pageContext.request.contextPath}/manager/BookServlet?op=deleteBook", {"id": id}, function (data) {

                    var $dom =JSON.parse(data);


                    layer.msg($dom["error"]);
                    window.location = "${pageContext.request.contextPath}/manager/BookServlet?op=listbook";

                });
            });

        });
    </script>


    <script src="${pageContext.request.contextPath}/lib/layui.all.js"></script>


<%@include file="/commons/footer.jsp" %>